/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pb138.webrep.util;

/**
 *
 * @author Odin
 */
public class Pair<L,R> {
    private L left;
    private R right;
    
    public static <L,R> Pair<L,R> of(L left, R right) {
        Pair<L,R> p = new Pair<>();
        p.left = left;
        p.right = right;
        return p;
    }
    public L getLeft() {
        return left;
    }
    public R getRight() {
        return right;
    }
    public L getKey() {
        return left;
    }
    public R getValue() {
        return right;
    }
    public int getHashCode() {
        return left.hashCode() + right.hashCode();
    }
    public boolean equals(Object obj) {
        if(obj instanceof Pair) return false;
        Pair<L,R> another = (Pair<L,R>) obj;
        if(left == null && another.getLeft() != null) return false;
        if(left != null && another.getLeft() == null) return false;
        if(right == null && another.getRight() != null) return false;
        if(right != null && another.getRight() == null) return false;
        if(!left.equals(another.getLeft()) || !right.equals(another.getRight())) return false;
        return true;
    }
    public String toString() {
        return "<"+ left.toString() +","+ right.toString() +">";
    }
}